//
//  UINavigationController+Category.m
//  jujing
//
//  Created by apple on 2021/11/11.
//

#import "UINavigationController+Category.h"

@implementation UINavigationController (Category)

- (void)pushViewControllerWithName:(NSString *)viewControllerName title:(nullable NSString *)title animated:(BOOL)animated {
    Class class = NSClassFromString(viewControllerName);
    if (class) {
        UIViewController *viewController = [[class alloc] init];
         viewController.title = title;
        viewController.hidesBottomBarWhenPushed = YES;
        [self pushViewController:viewController animated:animated];
    }
}

- (void)pushViewControllerWithName:(NSString *)viewControllerName {
    [self pushViewControllerWithName:viewControllerName title:nil animated:YES];
}

- (void)pushViewController:(UIViewController *)controller {
    controller.hidesBottomBarWhenPushed = YES;
    [self pushViewController:controller animated:YES];
}

- (void)popViewControllerToStringVc:(NSString *)vcname {
    for (UIViewController *vc in self.viewControllers) {
        if ([vc isKindOfClass:[NSClassFromString(vcname) class]]) {
            [self popToViewController:vc animated:YES];
            break;
        }
    }
}

@end
